package config

import (
	"github.com/zeromicro/go-zero/core/logx"
	"github.com/zeromicro/go-zero/rest"
	"github.com/zeromicro/go-zero/zrpc"
)

type Config struct {
	rest.RestConf
	CustomLog logx.LogConf

	// user rpc config
	UserRpc zrpc.RpcClientConf

	// common rpc config
	CommonRpc zrpc.RpcClientConf

	// order rpc config
	OrderRpc zrpc.RpcClientConf

	// inventory rpc config
	InventoryRpc zrpc.RpcClientConf

	Env string

	// redis config
	RedisConf struct {
		Mode string
		Dev  struct {
			Single struct {
				Host     string
				Password string
				Db       uint8
			}

			Replication struct {
				Host     string
				Password string
				Db       uint8
			}

			Sentinel struct {
				Host       []string
				Password   string
				MasterName string
				Db         uint8
			}

			Cluster struct {
				Host     []string
				Password string
				Db       uint8
			}
		}
		Test struct {
			Single struct {
				Host     string
				Password string
				Db       uint8
			}

			Replication struct {
				Host     string
				Password string
				Db       uint8
			}

			Sentinel struct {
				Host       []string
				Password   string
				MasterName string
				Db         uint8
			}

			Cluster struct {
				Host     []string
				Password string
				Db       uint8
			}
		}
		Prod struct {
			Single struct {
				Host     string
				Password string
				Db       uint8
			}

			Replication struct {
				Host     string
				Password string
				Db       uint8
			}

			Sentinel struct {
				Host       []string
				Password   string
				MasterName string
				Db         uint8
			}

			Cluster struct {
				Host     []string
				Password string
				Db       uint8
			}
		}
	}

	// mongo config
	MongoConf struct {
		Mode string
		Dev  struct {
			Single struct {
				Host string
			}
			Replication struct {
				Host string
			}
			Cluster struct {
				Host string
			}
		}

		Test struct {
			Single struct {
				Host string
			}
			Replication struct {
				Host string
			}
			Cluster struct {
				Host string
			}
		}

		Prod struct {
			Single struct {
				Host string
			}
			Replication struct {
				Host string
			}
			Cluster struct {
				Host string
			}
		}
	}

	// elasticsearch config
	EsConf struct {
		Dev struct {
			Host             []string
			Username         string
			Password         string
			NumberOfShards   int8
			NumberOfReplicas int8
			IsSsl            bool
			CertPath         string
		}
		Test struct {
			Host             []string
			Username         string
			Password         string
			NumberOfShards   int8
			NumberOfReplicas int8
			IsSsl            bool
			CertPath         string
		}
		Prod struct {
			Host             []string
			Username         string
			Password         string
			NumberOfShards   int8
			NumberOfReplicas int8
			IsSsl            bool
			CertPath         string
		}
	}

	// dtm config
	DtmConf struct {
		Dev struct {
			GrpcServer string
			HttpServer string
		}
		Test struct {
			GrpcServer string
			HttpServer string
		}
		Prod struct {
			GrpcServer string
			HttpServer string
		}
	}

	GrpcHost string
	GrpcPort int

	// limiter config
	LimiterConf struct {
		Mode string
		// 全局限流器
		GlobalLimiter struct {
			// 时间段：1表示1秒钟，60表示60秒(1分钟)
			Period int
			// 次数
			Quota int

			// 每秒生成的令牌数
			Rate int

			// 令牌桶最大容量
			Burst int
		}
		// IP限流器
		IpLimiter struct {
			// 时间段：1表示1秒钟，60表示60秒(1分钟)
			Period int
			// 次数
			Quota int

			// 每秒生成的令牌数
			Rate int

			// 令牌桶最大容量
			Burst int
		}
		// 用户限流器
		UserLimiter struct {
			// 时间段：1表示1秒钟，60表示60秒(1分钟)
			Period int
			// 次数
			Quota int

			// 每秒生成的令牌数
			Rate int

			// 令牌桶最大容量
			Burst int
		}
		// 关键操作限流器
		CriticalLimiter struct {
			// 时间段：1表示1秒钟，60表示60秒(1分钟)
			Period int
			// 次数
			Quota int

			// 每秒生成的令牌数
			Rate int

			// 令牌桶最大容量
			Burst int
		}
	}
}
